|
1
|
|
|
/* |
|
2
|
|
|
* Circles - Bring cloud-users closer together. |
|
3
|
|
|
* |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. See the COPYING file. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Maxence Lange <[email protected]> |
|
8
|
|
|
* @copyright 2017 |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** global: OC */ |
|
27
|
|
|
/** global: OCA */ |
|
28
|
|
|
/** global: Notyf */ |
|
29
|
|
|
|
|
30
|
|
|
/** global: actions */ |
|
31
|
|
|
/** global: nav */ |
|
32
|
|
|
/** global: elements */ |
|
33
|
|
|
/** global: curr */ |
|
34
|
|
|
/** global: api */ |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
var resultMembers = { |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
generateItemResult: function (search, value) { |
|
41
|
|
|
|
|
42
|
|
|
switch (value.type) { |
|
|
|
|
|
|
43
|
|
|
case define.typeUser: |
|
|
|
|
|
|
44
|
|
|
return resultMembers.generateItemUser(search, value); |
|
45
|
|
|
case define.typeGroup: |
|
46
|
|
|
return resultMembers.generateItemGroup(search, value); |
|
47
|
|
|
case define.typeContact: |
|
48
|
|
|
return resultMembers.generateItemContact(search, value); |
|
49
|
|
|
} |
|
|
|
|
|
|
50
|
|
|
}, |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
enhanceSearchResult: function (search, display) { |
|
54
|
|
|
display = escapeHTML(display); |
|
55
|
|
|
if (search.length > 0) { |
|
56
|
|
|
display = display.replace(new RegExp('(' + search + ')', 'gi'), '<b>$1</b>'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return display; |
|
60
|
|
|
}, |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
generateItemUser: function (search, value) { |
|
64
|
|
|
return '<div class="result_top">' + |
|
65
|
|
|
resultMembers.enhanceSearchResult(search, value.data.display) + '</div>' + |
|
66
|
|
|
'<div class="result_bot">' + t('circles', 'Local User') + '</div>'; |
|
67
|
|
|
}, |
|
68
|
|
|
|
|
69
|
|
|
generateItemGroup: function (search, value) { |
|
70
|
|
|
return '<div class="result_top">' + |
|
71
|
|
|
resultMembers.enhanceSearchResult(search, value.data.display) + '</div>' + |
|
72
|
|
|
'<div class="result_bot">' + t('circles', 'Local Group') + '</div>'; |
|
73
|
|
|
}, |
|
74
|
|
|
|
|
75
|
|
|
generateItemContact: function (search, value) { |
|
76
|
|
|
var display = resultMembers.enhanceSearchResult(search, value.data.display); |
|
77
|
|
|
var email = resultMembers.enhanceSearchResult(search, value.data.email); |
|
78
|
|
|
var org = resultMembers.enhanceSearchResult(search, value.data.organization); |
|
79
|
|
|
if (email !== '') { |
|
80
|
|
|
email = ' - ' + email; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (org !== '') { |
|
84
|
|
|
display += ' (' + org + ')'; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return '<div class="result_top">' + display + '</div>' + |
|
88
|
|
|
'<div class="result_bot">' + t('circles', 'Contact') + email + '</div>'; |
|
89
|
|
|
}, |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
searchMembersResult: function (response) { |
|
93
|
|
|
|
|
94
|
|
|
elements.membersSearchResult.children().remove(); |
|
95
|
|
|
|
|
96
|
|
|
if (response === null) { |
|
97
|
|
|
elements.membersSearchResult.fadeOut(0); |
|
98
|
|
|
return; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
var currSearch = response.search; |
|
102
|
|
|
$.each(response.result, function (index, value) { |
|
103
|
|
|
elements.membersSearchResult.append('<div class="members_search" data-type="' + |
|
104
|
|
|
value.type + '" data-ident="' + escapeHTML(value.ident) + '">' + |
|
105
|
|
|
resultMembers.generateItemResult(currSearch, value) + '</div>'); |
|
106
|
|
|
}); |
|
107
|
|
|
|
|
108
|
|
|
$('.members_search').on('click', function () { |
|
109
|
|
|
var ident = $(this).attr('data-ident'); |
|
110
|
|
|
var type = $(this).attr('data-type'); |
|
111
|
|
|
|
|
112
|
|
|
if (Number(type) === define.typeGroup) { |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
OC.dialogs.confirm( |
|
115
|
|
|
t('circles', |
|
116
|
|
|
'This operation will add/invite all members of the group to the circle'), |
|
117
|
|
|
t('circles', 'Please confirm'), |
|
118
|
|
|
function (e) { |
|
119
|
|
|
if (e === true) { |
|
120
|
|
|
api.addMember(curr.circle, ident, type, resultMembers.addMemberResult); |
|
121
|
|
|
} |
|
122
|
|
|
}); |
|
123
|
|
|
|
|
124
|
|
|
} else { |
|
125
|
|
|
api.addMember(curr.circle, ident, type, resultMembers.addMemberResult); |
|
126
|
|
|
} |
|
127
|
|
|
}); |
|
128
|
|
|
|
|
129
|
|
|
// elements.fillMembersSearch('users', response.ocs.data.exact.users, |
|
130
|
|
|
// response.ocs.data.users); elements.fillMembersSearch('groups', |
|
131
|
|
|
// response.ocs.data.exact.groups, response.ocs.data.groups); if |
|
132
|
|
|
// (elements.membersSearchResult.children().length === 0) { |
|
133
|
|
|
// elements.membersSearchResult.fadeOut(0); return; } $('.members_search').on('click', |
|
134
|
|
|
// function () { curr.searchUserSelected = $(this).attr('searchresult'); if |
|
135
|
|
|
// ($(this).attr('source') === 'groups') { OC.dialogs.confirm( t('circles', 'This |
|
136
|
|
|
// operation will add/invite all members of the group to the circle'), t('circles', 'Please |
|
137
|
|
|
// confirm'), function (e) { if (e === true) { api.addGroupMembers(curr.circle, |
|
138
|
|
|
// curr.searchUserSelected, resultMembers.addGroupMembersResult); } }); } else { |
|
139
|
|
|
// api.addMember(curr.circle, curr.searchUserSelected, resultMembers.addMemberResult); } }); |
|
140
|
|
|
elements.membersSearchResult.fadeIn(300); |
|
141
|
|
|
}, |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
addMemberResult: function (result) { |
|
145
|
|
|
|
|
146
|
|
|
console.log(JSON.stringify(result)); |
|
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
resultMembers.addMemberUserResult(result); |
|
149
|
|
|
resultMembers.addMemberGroupResult(result); |
|
150
|
|
|
resultMembers.addMemberMailResult(result); |
|
151
|
|
|
resultMembers.addMemberContactResult(result); |
|
152
|
|
|
}, |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
addMemberUserResult: function (result) { |
|
156
|
|
|
if (result.user_type !== define.typeUser) { |
|
|
|
|
|
|
157
|
|
|
return; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
if (curr.circleDetails.type === define.typeClosed) { |
|
161
|
|
|
resultMembers.inviteMemberResult(result); |
|
162
|
|
|
return; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
if (result.status === 1) { |
|
166
|
|
|
OCA.notification.onSuccess( |
|
167
|
|
|
t('circles', "The member '{name}' was added to the circle", |
|
168
|
|
|
{name: result.display})); |
|
169
|
|
|
|
|
170
|
|
|
nav.displayMembers(result.members); |
|
171
|
|
|
return; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
OCA.notification.onFail( |
|
175
|
|
|
t('circles', "The member '{name}' could not be added to the circle", |
|
176
|
|
|
{name: result.display}) + |
|
177
|
|
|
': ' + ((result.error) ? result.error : t('circles', 'no error message'))); |
|
178
|
|
|
}, |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
addMemberMailResult: function (result) { |
|
182
|
|
|
if (result.user_type !== define.typeMail) { |
|
|
|
|
|
|
183
|
|
|
return; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (result.status === 1) { |
|
187
|
|
|
OCA.notification.onSuccess( |
|
188
|
|
|
t('circles', "The email address '{email}' was added to the circle", |
|
189
|
|
|
{email: result.display})); |
|
190
|
|
|
|
|
191
|
|
|
nav.displayMembers(result.members); |
|
192
|
|
|
return; |
|
193
|
|
|
} |
|
194
|
|
|
OCA.notification.onFail( |
|
195
|
|
|
t('circles', "The email address '{email}' could not be added to the circle", |
|
196
|
|
|
{email: result.display}) + |
|
197
|
|
|
': ' + ((result.error) ? result.error : t('circles', 'no error message'))); |
|
198
|
|
|
}, |
|
199
|
|
|
|
|
200
|
|
|
addMemberContactResult: function (result) { |
|
201
|
|
|
if (result.user_type !== define.typeContact) { |
|
|
|
|
|
|
202
|
|
|
return; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
if (result.status === 1) { |
|
206
|
|
|
OCA.notification.onSuccess( |
|
207
|
|
|
t('circles', "The contact '{contact}' was added to the circle", |
|
208
|
|
|
{contact: result.display})); |
|
209
|
|
|
|
|
210
|
|
|
nav.displayMembers(result.members); |
|
211
|
|
|
return; |
|
212
|
|
|
} |
|
213
|
|
|
OCA.notification.onFail( |
|
214
|
|
|
t('circles', "The contact '{contact}' could not be added to the circle", |
|
215
|
|
|
{contact: result.display}) + |
|
216
|
|
|
': ' + ((result.error) ? result.error : t('circles', 'no error message'))); |
|
217
|
|
|
}, |
|
218
|
|
|
|
|
219
|
|
|
|
|
220
|
|
|
inviteMemberResult: function (result) { |
|
221
|
|
|
|
|
222
|
|
|
if (result.status === 1) { |
|
223
|
|
|
OCA.notification.onSuccess( |
|
224
|
|
|
t('circles', "The member '{name}' was invited to the circle", |
|
225
|
|
|
{name: result.display})); |
|
226
|
|
|
|
|
227
|
|
|
nav.displayMembers(result.members); |
|
228
|
|
|
return; |
|
229
|
|
|
} |
|
230
|
|
|
OCA.notification.onFail( |
|
231
|
|
|
t('circles', "The member '{name}' could not be invited to the circle", |
|
232
|
|
|
{name: result.display}) + |
|
233
|
|
|
': ' + ((result.error) ? result.error : t('circles', 'no error message'))); |
|
234
|
|
|
}, |
|
235
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
addMemberGroupResult: function (result) { |
|
238
|
|
|
|
|
239
|
|
|
if (result.user_type !== define.typeGroup) { |
|
|
|
|
|
|
240
|
|
|
return; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
if (curr.circleDetails.type === define.typeClosed) { |
|
244
|
|
|
resultMembers.inviteMemberGroupResult(result); |
|
245
|
|
|
return; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
if (result.status === 1) { |
|
249
|
|
|
OCA.notification.onSuccess( |
|
250
|
|
|
t('circles', "Members of the group '{name}' were added to the circle", |
|
251
|
|
|
{name: result.display})); |
|
252
|
|
|
|
|
253
|
|
|
nav.displayMembers(result.members); |
|
254
|
|
|
return; |
|
255
|
|
|
} |
|
256
|
|
|
OCA.notification.onFail( |
|
257
|
|
|
t('circles', "Members of the group '{name}' could not be added to the circle", |
|
258
|
|
|
{name: result.display}) + |
|
259
|
|
|
': ' + |
|
260
|
|
|
((result.error) ? result.error : t('circles', 'no error message'))); |
|
261
|
|
|
}, |
|
262
|
|
|
|
|
263
|
|
|
|
|
264
|
|
|
inviteMemberGroupResult: function (result) { |
|
265
|
|
|
|
|
266
|
|
|
if (result.status === 1) { |
|
267
|
|
|
OCA.notification.onSuccess( |
|
268
|
|
|
t('circles', "Members of the group '{name}' were invited to the circle", |
|
269
|
|
|
{name: result.display})); |
|
270
|
|
|
|
|
271
|
|
|
nav.displayMembers(result.members); |
|
272
|
|
|
return; |
|
273
|
|
|
} |
|
274
|
|
|
OCA.notification.onFail( |
|
275
|
|
|
t('circles', "Members of the group '{name}' could not be invited to the circle", |
|
276
|
|
|
{name: result.display}) + |
|
277
|
|
|
': ' + |
|
278
|
|
|
((result.error) ? result.error : t('circles', 'no error message'))); |
|
279
|
|
|
}, |
|
280
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
removeMemberResult: function (result) { |
|
283
|
|
|
if (result.status === 1) { |
|
284
|
|
|
|
|
285
|
|
|
elements.mainUIMembersTable.children("[member-id='" + result.user_id + "']").each( |
|
286
|
|
|
function () { |
|
287
|
|
|
if (Number($(this).attr('member-type')) === result.user_type) { |
|
288
|
|
|
$(this).hide(300); |
|
289
|
|
|
} |
|
290
|
|
|
}); |
|
291
|
|
|
OCA.notification.onSuccess( |
|
292
|
|
|
t('circles', "The member '{name}' was removed from the circle", |
|
293
|
|
|
{name: result.display})); |
|
294
|
|
|
return; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
OCA.notification.onFail( |
|
298
|
|
|
t('circles', "The member '{name}' could not be removed from the circle", |
|
299
|
|
|
{name: result.display}) + |
|
300
|
|
|
': ' + |
|
301
|
|
|
((result.error) ? result.error : t('circles', 'no error message'))); |
|
302
|
|
|
}, |
|
303
|
|
|
|
|
304
|
|
|
levelMemberResult: function (result) { |
|
305
|
|
|
if (result.status === 1) { |
|
306
|
|
|
OCA.notification.onSuccess( |
|
307
|
|
|
t('circles', "Member '{name}' updated", |
|
308
|
|
|
{name: result.display})); |
|
309
|
|
|
|
|
310
|
|
|
nav.displayMembers(result.members); |
|
311
|
|
|
return; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
nav.displayMembers(''); |
|
315
|
|
|
OCA.notification.onFail( |
|
316
|
|
|
t('circles', "The member '{name}' could not be updated", {name: result.display}) + |
|
317
|
|
|
': ' + |
|
318
|
|
|
((result.error) ? result.error : t('circles', 'no error message'))); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
}; |
|
322
|
|
|
|